package cn.tedu.account.tx;

import cn.tedu.account.entity.AccountMessage;
import cn.tedu.account.service.AccountService;
import cn.tedu.account.util.JsonUtil;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @ClassName AccountConsumer
 * @Description:类描述
 * @Author Tedu
 * @Date 2021/7/6 15:30
 * @Version V1.0
 **/
@Component
@RocketMQMessageListener(topic = "orderTopic",consumerGroup = "accountGroup")
public class AccountConsumer implements RocketMQListener<String> {
@Autowired
private AccountService accountService;
    @Override
    public void onMessage(String json) {
        // json --> AccountMessage
        AccountMessage am = JsonUtil.from(json, AccountMessage.class);
        // json --> AccountMessage
        accountService.decrease(am.getUserId(), am.getMoney());

    }
}
